<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>潮人电商后台</title>
    <link rel="stylesheet" href="css/style.css"/>
    <script type="text/javascript" src="/js/jquery.js"></script>
</head>
<body class="login_bg">
    <section class="loginBox">
        <header class="loginHeader">
            <h1>潮人管理系统</h1>
        </header>
        <section class="loginCont">
            <form id="login" class="loginForm" action="welcome.html">
                <div class="inputbox">
                    <label for="user">用户名：</label>
                    <input id="user" type="text" name="uAccount" placeholder="请输入用户名" required onchange="verify()"/>
                </div>
                <div class="inputbox">
                    <label for="mima">密码：</label>
                    <input id="mima" type="password" name="uPassword" placeholder="请输入密码" required/>
                </div>
                <div class="subBtn">
                    <input type="button" value="登录"  onclick="login()"/>
                    <input type="button" value="注册"  onclick="zhuche()"/>
                    <input type="reset" value="重置"/>

                </div>

            </form>
        </section>
    </section>

<script>
      function login() {

          $.ajax({
              url:"/loginAccount",
              type:"post",
              data:$("#login").serialize(),
              success:function (data) {

                  if (data.code==1){
                      alert(data.msg);
                  }
                  if (data.code==0){
                      alert("登录成功");
                      location.href="http://localhost:8080/indexPage";
                  }

                  if (data.code==2){
                      alert(data.msg);
                  }
                  if (data.code==3){

                      alert(data.msg);
                  }

                  if (data.code==4){

                      alert(data.msg);
                  }

              }
          })
      }

      function zhuche() {

           if (confirm("即将跳转到注册页面")){
               location.href="http://localhost:8080/registPage";
           }
      }


      function verify() {

              var user = $("#user").val();
          $.ajax({

              url:"/verifyUser",
              type:"post",
              data:"uAccount="+user,
              success:function (data) {

                  if (data.code==1) {

                      alert("请输入用户名");
                  }

                  if (data.code==2) {

                      alert("账号错误");
                  }


                  if (data.code==0){

                      alert("您是超级管理员");
                  }

                  if (data.code==4){

                      alert("您是普通管理员");
                  }
              }

          })

      }
</script>
</body>
</html>